
import {
  getMemberWithdrawRequest
} from '../../api/user'

Page({
  data: {
    pageNo: 1,
    pageSize: 10,
    dataArr: [],
    bottomIsLoadingHidden: false,
    isLoadingText: '没有数据啦~',
    isEmptyData: true
  },

  onLoad: function (options) {

    tt.setNavigationBarTitle({
      title: '提现明细' // 导航栏标题
    });

    tt.showLoading({
      title: '加载中', // 内容
      success: (res) => {

      }
    });

    this.loadMore()
  },

  /** 获取数据 */
  loadMore: function () {
    let params = {
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize,
    };
    getMemberWithdrawRequest(params).then((res) => {

      let list = (res.result && res.result.data) || [];
      this.setData({
        isLoadingText: list.length > 0 ? '加载中...' : '没有数据啦~'
      })
      if (this.data.pageNo > 1) {
        //追加数据
        this.setData({
          dataArr: this.data.dataArr.concat(list)
        })
      } else {
        this.setData({ dataArr: list });
        //隐藏导航条加载动画
        tt.hideNavigationBarLoading();
        //停止下拉刷新
        tt.stopPullDownRefresh();
      }

      this.bottomIsLoadingHidden = this.data.dataArr.length == this.data.pageSize || this.data.dataArr.length == 0;

      tt.hideLoading();

      this.setData({
        isEmptyData: this.data.dataArr.length > 0
      })

    }).catch((res) => {
      console.log('getMemberWithdrawRequest请求失败')
      console.log(res)
      tt.hideLoading();
    })
  },

  /** 页面相关事件处理函数--监听用户下拉动作 */
  onPullDownRefresh: function () {
    tt.startPullDownRefresh();
    console.log('onPullDownRefresh')
    this.setData({
      pageNo: 1,
      dataArr: []
    })
    this.loadMore()
  },

  /** 页面上拉触底事件的处理函数 */
  onReachBottom: function () {
    console.log('onReachBottom')
    let pageIndex = this.data.pageNo;
    this.setData({
      pageNo: pageIndex + 1
    })
    // this.loadMore();
  },
})